﻿using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using RestfulApiV1.Data.Entity;
using RestfulApiV1.Implement.Paged;
using RestfulApiV1.Interface.Data;
using RestfulApiV1.Utils.Json;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace RestfulApiV1.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ArticleController : ControllerBase
    {
        private readonly IRespository<Article> _articleRespository;

        // GET: api/<ArticleController>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/<ArticleController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            var list = _articleRespository.Table
                .Where(x => x.IsDeleted == false);

            ////return Ok(new { code = 1000, data = GetDynamic(new Pagination<Article>(list, id), })
            return JsonHelper.SerializeObject(list);

        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet, Route("getArrticleInfo")]
        public ActionResult GetUserInfo(string token)
        {
            var jwtInfo = new JwtSecurityToken(token);
            var userIdString = jwtInfo.Claims.FirstOrDefault(x => x.Type == "userId").Value;
            var userId = int.Parse(userIdString);

            var accessList = new List<string>
            {
                "dashboard",
                //"users",
                "roles",
                "setting"

            };

        dynamic info;
            var user = _articleRespository.GetById(userId);

            //var info = new
            
            return Ok(new { code = 1000, data = "", msg = "获取用户信息成功" });
            //return Ok(new { accessToken = token, refreshToken });
        }

        // POST api/<ArticleController>
        [HttpPost]
        public void Post([FromBody] string value)
        {

        }

        // PUT api/<ArticleController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {

        }

        // DELETE api/<ArticleController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {

        }


    }
}
